<template>
  <div class="applyshop">
    <div class="container">
      <h2>{{$t('fabi.apply[0]')}}</h2>
      <div class="text">{{$t('fabi.apply[1]')}}</div>
      <div class="menu">
        <div class="item" @click="publish('tosell')">
          <img src="../../assets/img/shop-sell.png" alt />
          <p class="tit">{{$t('fabi.apply[2]')}}</p>
        </div>
        <div class="item" @click="publish('tobuy')">
          <img src="../../assets/img/shop-buy.png" alt />
          <p class="tit">{{$t('fabi.apply[3]')}}</p>
        </div>
      </div>
      <h3 v-if="isShop == 1">{{$t('fabi.apply[4]')}}</h3>
      <h3 v-else-if="isShop == 2 || isShop == 6"  @click="cancel">{{$t('fabi.apply[5]')}}</h3>
      <h3 v-else-if="isShop == 3">{{$t('fabi.apply[6]')}}</h3>
      <h3 v-else-if="isShop == 4">{{$t('fabi.apply[7]')}}</h3>
      <h3 v-else  @click="publish()">{{$t('fabi.apply[8]')}}</h3>
      <div class="longtext">{{$t('fabi.apply[9]')}}</div>
      <el-button type="primary" v-if="isShop == 2 || isShop == 6" @click="cancel">{{$t('fabi.apply[10]')}}</el-button>
      <el-button type="primary" v-if="isShop == 3" @click="publish()">{{$t('fabi.apply[11]')}}</el-button>
      
    </div>
    <!-- quren框 -->
    <el-dialog :title="$t('fabi.apply[11]')" width="36%" top="25vh" center :visible.sync="showDialog">
      <ul class="step">
        <li>
          <p class="title">{{$t('fabi.apply[12]')}}</p>
          <p class="con">{{$t('fabi.apply[13]')}} </p>
        </li>
        <li>
          <p class="title">{{$t('fabi.apply[14]')}}</p>
          <p class="con">{{$t('fabi.apply[15]')}}</p>
        </li>
      </ul>
      <div slot="footer" class="dialog-footer">
        <div class="agree">
          <el-checkbox v-model="checked">{{$t('fabi.apply[16]')}}{{pagedata.amount}}USDT{{$t('fabi.apply[17]')}}</el-checkbox>
        </div>
        <el-button type="primary" :disabled="!checked" @click="submit">{{$t('fabi.apply[18]')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { details } from "@/api/user";
import { shopapplyindex, shopapply, shopcancel } from "@/api/fbTrade";
export default {
  name: "applyshop",
  data() {
    return {
      showDialog: false,
      checked: false,
      pagedata: {
        amount: 1000,
        content: "",
      },
      isShop: 0,
      userInfo: {
        phone_bind: '',
        authentication: '',
      }
    };
  },
  created() {
      shopapplyindex().then((res) => {
          
              this.pagedata = res ;
        
      });
        this.getStatus();
  },
  methods: {
    publish(which){
      if(this.userInfo.phone_bind != 1){
        this.$message.error(this.$t('fabi.Tips[3]'));
        return false;
      }
      if(this.userInfo.authentication == 0){
        this.$message.error(this.$t('fabi.Tips[4]'));
        return false;
      }
      if(this.isShop == 1){
          this.$message.error(this.$t('fabi.Tips[5]'));
          return false;
      }
      // if(this.isShop == 3){
      //     this.$message.error('商家审核拒绝');
      //     return false;
      // }
      if(this.isShop == 4){
          this.$message.error(this.$t('fabi.Tips[6]'));
          return false;
      }
      if(this.isShop == 2 || this.isShop == 6){
          setTimeout(() => {
              this.$router.push({ path: which,});
          }, 800);
          return false
      }
        this.showDialog = true
        
    },
    getStatus() {
      details().then((res) => {
          
              this.isShop = res.config.fbshop;
              this.userInfo.phone_bind = res.config.phone_bind;
              this.userInfo.authentication = res.user.authentication;
           
      });
    },
    submit() {
        shopapply().then((res) => {
            
                this.$message.success("操作成功");
                this.$router.back();
             
        });
    },
    cancel() {
        shopcancel().then((res) => {
            
                this.$message.success("操作成功");
                this.getStatus();
             
        });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.applyshop {
  min-height: 790px;
  background-image: url(../../assets/img/shop-bg.png);
  background-size: cover;
  background-position: top center;
  color: #fff;
  text-align: center;
  .container {
    width: 750px;
    margin: 0 auto;
    overflow: hidden;
    padding: 100px 0;
    h2 {
      font-size: 50px;
    }
    .text {
      font-size: 20px;
      margin-top: 15px;
    }
    .menu {
      display: flex;
      justify-content: space-around;
      margin-top: 60px;
      .item {
        width: 258px;
        height: 287px;
        background-image: url(../../assets/img/shop-block.png);
        background-size: 100% 100%;
        img {
          width: 82px;
          margin-top: 50px;
        }
        .tit {
          font-size: 20px;
          margin-top: 10px;
        }
      }
    }
    h3 {
      font-size: 20px;
      margin-top: 60px;
    }
    .longtext {
      text-align: left;
      text-indent: 2em;
      margin-top: 30px;
      font-size: 14px;
    }
  }
  .step {
    li {
      background-color: #131c28;
      margin-top: 10px;
      padding: 15px;
      color: #fff;
      .title {
        color: #6185e5;
        font-size: 16px;
      }
      .con {
        margin-top: 10px;
      }
    }
  }
  .agree {
    text-align: left;
  }
  button {
    width: 200px;
    margin-top: 20px;
  }
}
</style>
